home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / SDKs / Apple Game Sprockets / InputSprocket / Sample Drivers / Common Driver Code / DialogUtils.cp < prev    next >
Encoding:
Text File  |  1998-07-14  |  47.6 KB  |  1,485 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************
  2.  
  3. File:      DialogUtilities.cp
  4.  
  5. Copyright © 1996, 1997, 1998 Apple Computer, Inc., All Rights Reserved
  6.  
  7.  
  8. You may incorporate this sample code into your applications without
  9. restriction, though the sample code has been provided "AS IS" and the
  10. responsibility for its operation is 100% yours.  However, what you are
  11. not permitted to do is to redistribute the source as "DSC Sample Code"
  12. after having made changes. If you're going to re-distribute the source,
  13. we require that you make it clear in the source that the code was
  14. descended from Apple Sample Code, but that you've made changes.
  15.  
  16. *************************************************************************************/
  17. #ifndef __PALETTES__
  18. #include <Palettes.h>
  19. #endif
  20.  
  21. #ifndef __FONTS__
  22. #include <Fonts.h>
  23. #endif
  24.  
  25. #ifndef __TEXTUTILS__
  26. #include <TextUtils.h>
  27. #endif
  28.  
  29. #ifndef __WINDOWS__
  30. #include <Windows.h>
  31. #endif
  32.  
  33. // nothing here should be speed dependent
  34. #if __MWERKS__
  35. #pragma optimize_for_size on
  36. #endif
  37.  
  38. #include "DialogUtils.h"
  39.  
  40. // debug mode turns on assertions
  41. #ifndef DEBUG
  42. #define DEBUG 0
  43. #endif
  44.  
  45. /*
  46.  * safe turns on extra (theoretically unneeded) error checking
  47.  * all the errors that it handles are ones that would generate assertions
  48.  * it is a saftey vs code size (about 5k for all the functions) decision
  49.  */
  50.  
  51. #ifndef SAFE
  52. #define SAFE 1            
  53. #endif
  54.  
  55. #ifdef UNIVERSAL_INTERFACES_VERSION
  56. typedef UInt32    DelayType;
  57. #else
  58. typedef SInt32    DelayType;
  59. #endif
  60.  
  61. /*
  62.  *
  63.  * Here are our assertion style macros.  We use these to do the parameter
  64.  * validation and extra error checking (the sort of things the toolbox
  65.  * doesn't do and that really aren't required.  (example making sure
  66.  * when you animate a button click that the item is actually a button).
  67.  *
  68.  */
  69.  
  70. #if DEBUG
  71.     #define DUASSERT_RETVAL(test,str,err)    {if(!(test)){DebugStr("\p" #str ); return (err);}}
  72.     #define DUASSERT_RET(test,str)            {if(!(test)){DebugStr("\p" #str ); return;}}
  73.     #define DUASSERT(test, str)                {if(!(test)){DebugStr("\p" #str);}}
  74. #elif SAFE
  75.     #define DUASSERT_RETVAL(test,str,err)    {if(!(test)){ return (err);}}
  76.     #define DUASSERT_RET(test,str)            {if(!(test)){ return; }}
  77.     #define DUASSERT(test, str)                ((void)0)
  78. #else
  79.     #define DUASSERT_RETVAL(test,str,err)    ((void)0)
  80.     #define DUASSERT_RET(test,str)            ((void)0)
  81.     #define DUASSERT(test, str)                ((void)0)
  82. #endif
  83.  
  84. pascal void     OKUserProc(DialogPtr inDialog, DialogItemIndex inItem);
  85. pascal void     PrimaryGroupUserProc(DialogPtr inDialog, DialogItemIndex inItem);
  86. pascal void     SecondaryGroupUserProc(DialogPtr inDialog, DialogItemIndex inItem);
  87. pascal Boolean     ModernStdFilterProc(DialogPtr inDialog, EventRecord *inEvent, DialogItemIndex *inItem);
  88.  
  89. #if GENERATINGCFM
  90. RoutineDescriptor     OKUserProcRD                = BUILD_ROUTINE_DESCRIPTOR(uppUserItemProcInfo, OKUserProc);
  91. RoutineDescriptor     SecondaryGroupUserProcRD    = BUILD_ROUTINE_DESCRIPTOR(uppUserItemProcInfo,    SecondaryGroupUserProc);
  92. RoutineDescriptor     PrimaryGroupUserProcRD        = BUILD_ROUTINE_DESCRIPTOR(uppUserItemProcInfo, PrimaryGroupUserProc);
  93. RoutineDescriptor     ModernStdFilterProcRD        = BUILD_ROUTINE_DESCRIPTOR(uppModalFilterProcInfo, ModernStdFilterProc);
  94.  
  95. UserItemUPP            OKUserProcUPP                = &OKUserProcRD;        
  96. UserItemUPP            SecondaryGroupUserProcUPP    = &SecondaryGroupUserProcRD;        
  97. UserItemUPP            PrimaryGroupUserProcUPP        = &PrimaryGroupUserProcRD;        
  98. ModalFilterUPP        ModernStdFilterProcUPP        = &ModernStdFilterProcRD;
  99. #else
  100. UserItemUPP            OKUserProcUPP                = OKUserProc;        
  101. UserItemUPP            SecondaryGroupUserProcUPP    = SecondaryGroupUserProc;        
  102. UserItemUPP            PrimaryGroupUserProcUPP        = PrimaryGroupUserProc;        
  103. ModalFilterUPP        ModernStdFilterProcUPP        = ModernStdFilterProc;
  104. #endif
  105.  
  106. /* =============================================================================
  107.  *        OKUserProc (internal)
  108.  *
  109.  *    Draws the user item used for framing the OK button.  The user item should
  110.  *    be four pixels larger than the OK button in each direction.
  111.  * ========================================================================== */
  112.  
  113. pascal void OKUserProc(
  114.     DialogPtr            inDialog,
  115.     DialogItemIndex            inItem)
  116. {
  117.     DUASSERT_RET(inDialog != nil,                    "OKUserProc inDialog == nil");
  118.     DUASSERT_RET(isDialogWindow(inDialog),            "OKUserProc inDialog is not a dialog"); 
  119.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "OKUserProc inItem > CountDITL(inDialog)");
  120.     DUASSERT_RET(inItem > 0,                        "OKUserProc inItem <= 0");
  121.  
  122.     Rect                rect;
  123.     
  124.     DialogItem_GetRect(inDialog, inItem, &rect);
  125.     
  126.     PenSize(3, 3);
  127.     FrameRoundRect(&rect, 16, 16);
  128.     PenSize(1, 1);
  129. }
  130.  
  131. /* =============================================================================
  132.  *        PrimaryGroupUserProc (internal)
  133.  *
  134.  * ========================================================================== */
  135.  
  136. pascal void PrimaryGroupUserProc(
  137.     DialogPtr            inDialog,
  138.     DialogItemIndex            inItem)
  139. {
  140.     DUASSERT_RET(inDialog != nil,                    "PrimaryGroupUserProc inDialog == nil");
  141.     DUASSERT_RET(isDialogWindow(inDialog),            "PrimaryGroupUserProc inDialog is not a dialog"); 
  142.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "PrimaryGroupUserProc inItem > CountDITL(inDialog)");
  143.     DUASSERT_RET(inItem > 0,                        "PrimaryGroupUserProc inItem <= 0");
  144.  
  145.     Rect                rect;
  146.     GScActiveType        active = kGSInactive;
  147.         
  148.     DialogItem_GetRect(inDialog, inItem, &rect);
  149.     if (FrontWindow() == inDialog) { active = kGSActive; }
  150.  
  151.     GScGroupBox_PrimarySimple_Draw(&rect, active);
  152. }
  153.  
  154. /* =============================================================================
  155.  *        SecondaryGroupProc (internal)
  156.  *
  157.  * ========================================================================== */
  158.  
  159. pascal void SecondaryGroupUserProc(
  160.     DialogPtr            inDialog,
  161.     DialogItemIndex            inItem)
  162. {
  163.     DUASSERT_RET(inDialog != nil,                    "SecondaryGroupUserProc inDialog == nil");
  164.     DUASSERT_RET(isDialogWindow(inDialog),            "SecondaryGroupUserProc inDialog is not a dialog"); 
  165.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "SecondaryGroupUserProc inItem > CountDITL(inDialog)");
  166.     DUASSERT_RET(inItem > 0,                        "SecondaryGroupUserProc inItem <= 0");
  167.  
  168.     Rect                rect;
  169.     GScActiveType        active = kGSInactive;
  170.         
  171.     DialogItem_GetRect(inDialog, inItem, &rect);
  172.     if (FrontWindow() == inDialog) { active = kGSActive; }
  173.     
  174.     GScGroupBox_SecondarySimple_Draw(&rect, active);
  175. }
  176.  
  177.  
  178. pascal Boolean ModernStdFilterProc(
  179.     DialogPtr            inDialog, 
  180.     EventRecord*        inEvent,
  181.     DialogItemIndex*            outItem)
  182. {
  183.     DUASSERT_RETVAL(inDialog != nil,                "ModernStdFilterProc inDialog == nil", false);
  184.     DUASSERT_RETVAL(isDialogWindow(inDialog),        "ModernStdFilterProc inDialog is not a dialog", false);
  185.     DUASSERT_RETVAL(inEvent != nil,                    "ModernStdFilterProc inEvent == nil", false);
  186.     DUASSERT_RETVAL(outItem != nil,                    "ModernStdFilterProc outItem == nil", false);
  187.  
  188.     Boolean handled = false;
  189.     *outItem = 0;
  190.     
  191.     switch(inEvent->what)
  192.     {
  193.         case keyDown:    
  194.             handled = FilterKeyEvent(inDialog, inEvent, outItem);
  195.             break;
  196.     }
  197.             
  198.     // if did not handled it let the standard filter proc handled it
  199.     if (!handled)
  200.     {
  201.         handled = StdFilterProc(inDialog, inEvent, outItem);
  202.     }
  203.         
  204.     return handled;
  205. }
  206.  
  207.  
  208. static inline Boolean CheckKeyMap(unsigned char *keyMap, UInt32 scanCode)
  209. {
  210.     return ((keyMap[scanCode >> 3]) >> (scanCode & 7) & 1);
  211. }
  212.  
  213. EventModifiers GetKeyModifiers(void)
  214. {
  215.     UInt16            modifiers = 0;
  216.     UInt8             keyMap[16];    
  217.  
  218.     // bit positions in the keymap of the modifier keys
  219.     enum
  220.     {
  221.         kCommandKeyCode         = 55,
  222.         kLeftShiftKeyCode        = 56,
  223.         kLeftOptionKeyCode        = 58,
  224.         kLeftControlKeyCode        = 59,
  225.         
  226.         kRightShiftKeyCode        = 60,
  227.         kRightOptionKeyCode     = 61,
  228.         kRightControlKeyCode    = 62
  229.     };
  230.  
  231.     GetKeys ((long *) keyMap);
  232.  
  233.     if (CheckKeyMap(keyMap, kCommandKeyCode))         { modifiers |= cmdKey; }
  234.     if (CheckKeyMap(keyMap, kLeftShiftKeyCode))     { modifiers |= shiftKey; }
  235.     if (CheckKeyMap(keyMap, kLeftOptionKeyCode))     { modifiers |= optionKey; }
  236.     if (CheckKeyMap(keyMap, kLeftControlKeyCode))     { modifiers |= controlKey; }
  237.  
  238.     if (CheckKeyMap(keyMap, kRightShiftKeyCode))     { modifiers    |= rightShiftKey;    modifiers |= shiftKey; }
  239.     if (CheckKeyMap(keyMap, kRightOptionKeyCode))     { modifiers    |= rightOptionKey;    modifiers |= optionKey; }
  240.     if (CheckKeyMap(keyMap, kRightControlKeyCode))     { modifiers    |= rightControlKey;    modifiers |= controlKey; }
  241.  
  242.     return modifiers;
  243. }
  244.  
  245. Boolean    KeyEventOK(EventRecord *inEvent)
  246. {
  247.     DUASSERT_RETVAL(inEvent != nil,                "KeyEventOK inEvent is nil", false);
  248.     DUASSERT_RETVAL(keyDown == inEvent->what,    "KeyEventOK passed something other than keyDown", false);
  249.  
  250.     Boolean OKEvent = false;
  251.     
  252.     switch(inEvent->message & charCodeMask)
  253.     {
  254.         case 13:    // enterKey
  255.         case  3:    // returnKey
  256.             OKEvent = true;
  257.             break;
  258.     }
  259.     
  260.     return OKEvent;
  261. }
  262.  
  263. Boolean    KeyEventCancel(EventRecord *inEvent)
  264. {
  265.     DUASSERT_RETVAL(inEvent != nil,                "KeyEventCancel inEvent is nil", false);
  266.     DUASSERT_RETVAL(keyDown == inEvent->what,    "KeyEventCancel passed something other than keyDown", false);
  267.  
  268.     Boolean cancelEvent = false;
  269.     
  270.     switch(inEvent->message & charCodeMask)
  271.     {
  272.         case '.':    // command period
  273.             if (inEvent->modifiers & cmdKey) { cancelEvent = true; }
  274.             break;
  275.         
  276.         case 27:    // escape or clear
  277.             cancelEvent = true;
  278.             break;
  279.     }
  280.     
  281.     return cancelEvent;
  282. }
  283.  
  284. Boolean    FilterKeyEvent(DialogPtr inDialog, EventRecord *inEvent, DialogItemIndex *outItem)
  285. {
  286.     DUASSERT_RETVAL(inDialog != nil,                "FilterKeyEvent inDialog == nil", 0);
  287.     DUASSERT_RETVAL(isDialogWindow(inDialog),        "FilterKeyEvent inDialog is not a dialog", 0); 
  288.     DUASSERT_RETVAL(outItem != nil,                    "FilterKeyEvent outItem is nil", 0);
  289.     DUASSERT_RETVAL(inEvent != nil,                    "FilterKeyEvent inEvent is nil", 0);
  290.     DUASSERT_RETVAL(keyDown == inEvent->what,        "FilterKeyEvent passed something other than keyDown", 0);
  291.     
  292.     Boolean        handled = false;        // assume we won't handle it
  293.     DialogItemIndex     itemHit = 0;            // assume we didn't hit any item
  294.     
  295.     if (KeyEventOK(inEvent))
  296.     {
  297.         itemHit = GetDialogDefaultItem(inDialog);
  298.     }
  299.     else if (KeyEventCancel(inEvent))
  300.     {
  301.         itemHit = GetDialogCancelItem(inDialog);
  302.     }
  303.     
  304.     if (itemHit != 0)
  305.     {
  306.         DialogItem_AnimateButtonClick(inDialog, itemHit);
  307.  
  308.         *outItem    = itemHit;
  309.         handled        = true; 
  310.     }
  311.  
  312.     return handled;
  313. }
  314.  
  315. void DialogItem_SetUserProc(DialogRef inDialog, DialogItemIndex inItem, const UserItemUPP inUserProc)
  316. {    
  317.     DUASSERT_RET(inDialog != nil,                    "DialogItem_SetUserProc inDialog == nil");
  318.     DUASSERT_RET(isDialogWindow(inDialog),            "DialogItem_SetUserProc inDialog is not a dialog"); 
  319.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "DialogItem_SetUserProc inItem > CountDITL(inDialog)");
  320.     DUASSERT_RET(inItem > 0,                        "DialogItem_SetUserProc inItem <= 0");
  321.     
  322.     DialogItemType        type;
  323.     Handle                handle;
  324.     Rect                 rect;
  325.  
  326.     GetDialogItem(inDialog, inItem, &type, &handle, &rect);
  327.  
  328.     DUASSERT_RET(isUserType(type),    "DialogItem_SetUserProc item not a user item");
  329.     
  330.     SetDialogItem(inDialog, inItem, type, (Handle) inUserProc, &rect);
  331. }
  332.  
  333. void DialogItem_SetOKUserProc(DialogRef inDialog, DialogItemIndex inItem)
  334. {
  335.     DUASSERT_RET(inDialog != nil,                    "DialogItem_SetOKUserProc inDialog == nil");
  336.     DUASSERT_RET(isDialogWindow(inDialog),            "DialogItem_SetOKUserProc inDialog is not a dialog"); 
  337.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "DialogItem_SetOKUserProc inItem > CountDITL(inDialog)");
  338.     DUASSERT_RET(inItem > 0,                        "DialogItem_SetOKUserProc inItem <= 0");
  339.     
  340.     DialogItem_SetUserProc(inDialog, inItem, OKUserProcUPP);
  341. }
  342.  
  343. void DialogItem_SetPrimaryGroupUserProc(DialogRef inDialog, DialogItemIndex inItem)
  344. {
  345.     DUASSERT_RET(inDialog != nil,                    "DialogItem_SetPrimaryGroupUserProc inDialog == nil");
  346.     DUASSERT_RET(isDialogWindow(inDialog),            "DialogItem_SetPrimaryGroupUserProc inDialog is not a dialog"); 
  347.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "DialogItem_SetPrimaryGroupUserProc inItem > CountDITL(inDialog)");
  348.     DUASSERT_RET(inItem > 0,                        "DialogItem_SetPrimaryGroupUserProc inItem <= 0");
  349.     
  350.     DialogItem_SetUserProc(inDialog, inItem, PrimaryGroupUserProcUPP);
  351. }
  352.  
  353. void DialogItem_SetSecondaryGroupUserProc(DialogRef inDialog, DialogItemIndex inItem)
  354. {
  355.     DUASSERT_RET(inDialog != nil,                    "DialogItem_SetSecondaryGroupUserProc inDialog == nil");
  356.     DUASSERT_RET(isDialogWindow(inDialog),            "DialogItem_SetSecondaryGroupUserProc inDialog is not a dialog"); 
  357.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "DialogItem_SetSecondaryGroupUserProc inItem > CountDITL(inDialog)");
  358.     DUASSERT_RET(inItem > 0,                        "DialogItem_SetSecondaryGroupUserProc inItem <= 0");
  359.     
  360.     DialogItem_SetUserProc(inDialog, inItem, SecondaryGroupUserProcUPP);
  361. }
  362.  
  363. /*
  364.  *
  365.  * DialogItem_GetControl
  366.  *
  367.  */
  368.  
  369. typedef struct {
  370.     MenuHandle        mHandle;
  371.     short            mID;
  372. } PopupData, **PopupDataHandle;
  373.  
  374. MenuHandle DialogItem_GetPopupMenu(DialogRef inDialog, DialogItemIndex inItem)
  375. {
  376.     DUASSERT_RETVAL(inDialog != nil,                "DialogItem_GetPopupMenu inDialog == nil", nil);
  377.     DUASSERT_RETVAL(isDialogWindow(inDialog),        "DialogItem_GetPopupMenu inDialog is not a dialog",nil); 
  378.     DUASSERT_RETVAL(CountDITL(inDialog) >= inItem,    "DialogItem_GetPopupMenu inItem > CountDITL(inDialog)", nil);
  379.     DUASSERT_RETVAL(inItem > 0,                        "DialogItem_GetPopupMenu inItem <= 0", nil);
  380.  
  381.     DialogItemType        type;
  382.     Handle                handle;
  383.     Rect                rect;
  384.     
  385.     GetDialogItem(inDialog, inItem, &type, &handle, &rect);
  386.     
  387.     DUASSERT_RETVAL(isControlType(type),            "DialogItem_GetPopupMenu type was not a control type", nil);
  388.     DUASSERT_RETVAL(handle != nil,                    "DialogItem_GetPopupMenu handle was nil", nil);
  389.     DUASSERT_RETVAL(*handle != nil,                    "DialogItem_GetPopupMenu handle was purged", nil);
  390.  
  391.     MenuHandle        menuHandle         = nil;
  392.  
  393.     ControlHandle    controlHandle    = (ControlHandle) handle;
  394.     ControlPtr        controlPtr        = *controlHandle;
  395.     PopupDataHandle    popupHandle        = (PopupDataHandle) controlPtr->contrlData;
  396.     PopupData        *popupPtr        = *popupHandle;
  397.         
  398.     menuHandle = popupPtr->mHandle; 
  399.  
  400.     return menuHandle;
  401. }
  402.  
  403. void DialogItem_SetPopupMenu(DialogRef inDialog, DialogItemIndex inItem, MenuHandle inMenuHandle)
  404. {
  405.     DUASSERT_RET(inDialog != nil,                    "DialogItem_SetPopupMenu inDialog == nil");
  406.     DUASSERT_RET(isDialogWindow(inDialog),            "DialogItem_SetPopupMenu inDialog is not a dialog"); 
  407.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "DialogItem_SetPopupMenu inItem > CountDITL(inDialog)");
  408.     DUASSERT_RET(inItem > 0,                        "DialogItem_SetPopupMenu inItem <= 0");
  409.  
  410.     DialogItemType        type;
  411.     Handle                handle;
  412.     Rect                rect;
  413.     
  414.     GetDialogItem(inDialog, inItem, &type, &handle, &rect);
  415.     
  416.     DUASSERT_RET(isControlType(type),                "DialogItem_SetPopupMenu type was not a control type");
  417.     DUASSERT_RET(handle != nil,                        "DialogItem_SetPopupMenu handle was nil");
  418.     DUASSERT_RET(*handle != nil,                    "DialogItem_SetPopupMenu handle was purged");
  419.  
  420.     ControlHandle    controlHandle    = (ControlHandle) handle;
  421.     ControlPtr        controlPtr        = *controlHandle;
  422.     PopupDataHandle    popupHandle        = (PopupDataHandle) controlPtr->contrlData;
  423.     PopupData        *popupPtr        = *popupHandle;
  424.         
  425.     popupPtr->mHandle                = inMenuHandle;
  426. }
  427.  
  428. ControlHandle DialogItem_GetControl(DialogRef inDialog, DialogItemIndex inItem)
  429. {
  430.     DUASSERT_RETVAL(inDialog != nil,                "DialogItem_GetControl inDialog == nil", nil);
  431.     DUASSERT_RETVAL(isDialogWindow(inDialog),        "DialogItem_GetControl inDialog is not a dialog",nil); 
  432.     DUASSERT_RETVAL(CountDITL(inDialog) >= inItem,    "DialogItem_GetControl inItem > CountDITL(inDialog)", nil);
  433.     DUASSERT_RETVAL(inItem > 0,                        "DialogItem_GetControl inItem <= 0", nil);
  434.  
  435.     short            type;
  436.     Handle            handle;
  437.     Rect            rect;
  438.     
  439.     GetDialogItem(inDialog, inItem, &type, &handle, &rect);
  440.  
  441.     DUASSERT_RETVAL(isControlType(type),            "DialogItem_GetControl not a control item", nil);
  442.     DUASSERT_RETVAL(handle != nil,                    "DialogItem_GetControl handle was nil", nil);
  443.     DUASSERT_RETVAL(*handle != nil,                    "DialogItem_GetControl handle was purged", nil);
  444.     
  445.     ControlHandle controlHandle = nil;
  446.     
  447.     controlHandle = (ControlHandle) handle;
  448.     
  449.     return controlHandle;
  450. }
  451.  
  452.  
  453. void DialogItem_HiliteControl(DialogRef inDialog, DialogItemIndex inItem, ControlPartCode hiliteState)
  454. {
  455.     DUASSERT_RET(inDialog != nil,                    "DialogItem_HiliteControl inDialog == nil");
  456.     DUASSERT_RET(isDialogWindow(inDialog),            "DialogItem_HiliteControl inDialog is not a dialog"); 
  457.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "DialogItem_HiliteControl inItem > CountDITL(inDialog)");
  458.     DUASSERT_RET(inItem > 0,                        "DialogItem_HiliteControl inItem <= 0");
  459.  
  460.     ControlHandle control;
  461.     
  462.     control = DialogItem_GetControl(inDialog, inItem);
  463.  
  464.     DUASSERT_RET(control != nil,                    "DialogItem_HiliteControl control was nil");
  465.  
  466.     HiliteControl(control, hiliteState);
  467. }
  468.  
  469. void DialogItem_AnimateButtonClick(DialogRef inDialog, DialogItemIndex inItem)
  470. {
  471.     DUASSERT_RET(inDialog != nil,                    "DialogItem_AnimateButtonClick inDialog == nil");
  472.     DUASSERT_RET(isDialogWindow(inDialog),            "DialogItem_AnimateButtonClick inDialog is not a dialog"); 
  473.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "DialogItem_AnimateButtonClick inItem > CountDITL(inDialog)");
  474.     DUASSERT_RET(inItem > 0,                        "DialogItem_AnimateButtonClick inItem <= 0");
  475.  
  476.     short            type;
  477.     Handle            handle;
  478.     Rect            rect;
  479.     
  480.     GetDialogItem(inDialog, inItem, &type, &handle, &rect);
  481.     
  482.     DUASSERT_RET(isButtonType(type),                "DialogItem_AnimateButtonClick not a button item");
  483.     DUASSERT_RET(handle != nil,                        "DialogItem_AnimateButtonClick handle == nil");
  484.     DUASSERT_RET(*handle != nil,                    "DialogItem_AnimateButtonClick handle was purged");
  485.  
  486.     const UInt32    kDelayAmt         = 8;
  487.     DelayType        finalTicks;
  488.  
  489.     ControlHandle    controlHandle     = (ControlHandle) handle;
  490.  
  491.     HiliteControl(controlHandle, 1);
  492.     Delay(kDelayAmt, &finalTicks);
  493.     HiliteControl(controlHandle, 0);
  494. }
  495.  
  496. /*
  497.  *
  498.  *
  499.  * Disable/Enable dialog items
  500.  *
  501.  *
  502.  */
  503.  
  504. void DialogItem_Disable(DialogRef inDialog, DialogItemIndex inItem)
  505. {
  506.     DUASSERT_RET(inDialog != nil,                    "DialogItem_Disable inDialog == nil");
  507.     DUASSERT_RET(isDialogWindow(inDialog),            "DialogItem_Disable inDialog is not a dialog"); 
  508.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "DialogItem_Disable inItem > CountDITL(inDialog)");
  509.     DUASSERT_RET(inItem > 0,                        "DialogItem_Disable inItem <= 0");
  510.  
  511.     DialogItemType        type;
  512.     Handle                handle;
  513.     Rect                rect;
  514.     
  515.     GetDialogItem(inDialog, inItem, &type, &handle, &rect);
  516.     SetDialogItem(inDialog, inItem, type | kItemDisableBit, handle, &rect);
  517.  
  518.     if (isControlType(type))
  519.     {
  520.         DUASSERT_RET(handle != nil,                "DialogItem_Disable item is control but handle is nil");
  521.         
  522.         ControlHandle controlHandle = (ControlHandle) handle;
  523.  
  524.         HiliteControl(controlHandle, kControlInactivePart);
  525.     }        
  526. }
  527.  
  528. void DialogItem_Enable(DialogRef inDialog, DialogItemIndex inItem)
  529. {
  530.     DUASSERT_RET(inDialog != nil,                    "DialogItem_Enable inDialog == nil");
  531.     DUASSERT_RET(isDialogWindow(inDialog),            "DialogItem_Enable inDialog is not a dialog"); 
  532.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "DialogItem_Enable inItem > CountDITL(inDialog)");
  533.     DUASSERT_RET(inItem > 0,                        "DialogItem_Enable inItem <= 0");
  534.  
  535.     DialogItemType        type;
  536.     Handle                handle;
  537.     Rect                rect;
  538.     
  539.     GetDialogItem(inDialog, inItem, &type, &handle, &rect);
  540.     SetDialogItem(inDialog, inItem, type & ~kItemDisableBit, handle, &rect);
  541.  
  542.     if (isControlType(type))
  543.     {
  544.         DUASSERT_RET(handle != nil,                "DialogItem_Disable item is control but handle is nil");
  545.  
  546.         ControlHandle controlHandle = (ControlHandle) handle;
  547.         
  548.         HiliteControl(controlHandle, kControlNoPart);
  549.     }
  550. }
  551.  
  552. /*
  553.  *
  554.  *
  555.  * Getting/Setting dialog item text
  556.  *
  557.  */
  558.  
  559. void DialogItem_GetText(DialogRef inDialog, DialogItemIndex inItem, Str255 outText)
  560. {
  561.     DUASSERT_RET(inDialog != nil,                                "DialogItem_GetText inDialog == nil");
  562.     DUASSERT_RET(isDialogWindow(inDialog),                        "DialogItem_GetText inDialog is not a dialog"); 
  563.     DUASSERT_RET(CountDITL(inDialog) >= inItem,                    "DialogItem_GetText inItem > CountDITL(inDialog)");
  564.     DUASSERT_RET(inItem > 0,                                    "DialogItem_GetText inItem <= 0");
  565.     DUASSERT_RET(outText != nil,                                "DialogItem_GetText outText != nil");
  566.  
  567.     DialogItemType        type;
  568.     Handle                handle;
  569.     Rect                rect;
  570.     
  571.     GetDialogItem(inDialog, inItem, &type, &handle, &rect);
  572.  
  573.     Boolean staticTextItem    = isStaticTextType(type);
  574.     Boolean editTextItem    = isEditTextType(type);
  575.     Boolean controlItem        = isControlType(type);
  576.     
  577.     DUASSERT_RET(staticTextItem || editTextItem || controlItem,    "DialogItem_GetText item wrong type");
  578.     DUASSERT_RET(handle != nil,                                    "DialogItem_GetText item handle = nil");
  579.     DUASSERT_RET(*handle != nil,                                "DialogItem_GetText item handle was purged");
  580.  
  581.     outText[0] = 0;    // assume empty string
  582.  
  583.     if (staticTextItem || editTextItem)
  584.     {
  585.         GetDialogItemText(handle, outText);
  586.     }
  587.     
  588.     if (controlItem)
  589.     {
  590.         ControlHandle controlHandle = (ControlHandle) handle;
  591.         
  592.         GetControlTitle(controlHandle, outText);
  593.     }
  594. }
  595.  
  596. void DialogItem_SetText(DialogRef inDialog, DialogItemIndex inItem, const StringPtr inText)
  597. {
  598.     DUASSERT_RET(inDialog != nil,                                "DialogItem_SetText inDialog == nil");
  599.     DUASSERT_RET(isDialogWindow(inDialog),                        "DialogItem_SetText inDialog is not a dialog"); 
  600.     DUASSERT_RET(CountDITL(inDialog) >= inItem,                    "DialogItem_SetText inItem > CountDITL(inDialog)");
  601.     DUASSERT_RET(inItem > 0,                                    "DialogItem_SetText inItem <= 0");
  602.     DUASSERT_RET(inText != nil,                                    "DialogItem_SetText inText == nil");
  603.  
  604.     DialogItemType        type;
  605.     Handle                handle;
  606.     Rect                rect;
  607.     
  608.     GetDialogItem(inDialog, inItem, &type, &handle, &rect);
  609.  
  610.     Boolean staticTextItem    = isStaticTextType(type);
  611.     Boolean editTextItem    = isEditTextType(type);
  612.     Boolean controlItem        = isControlType(type);
  613.     
  614.     DUASSERT_RET(staticTextItem || editTextItem || controlItem,    "DialogItem_SetText item wrong type");
  615.     DUASSERT_RET(handle != nil,                                    "DialogItem_SetText item handle = nil");
  616.     DUASSERT_RET(*handle != nil,                                "DialogItem_SetText item handle was purged");
  617.  
  618.     if (staticTextItem || editTextItem)
  619.     {
  620.         SetDialogItemText(handle, inText);
  621.     }
  622.     
  623.     if (controlItem)
  624.     {
  625.         ControlHandle controlHandle = (ControlHandle) handle;
  626.  
  627.         SetControlTitle(controlHandle, inText);        
  628.     }
  629. }
  630.  
  631. void DialogItem_SetTextQuietly(DialogRef inDialog, DialogItemIndex inItem, const StringPtr inText)
  632. {
  633.     DUASSERT_RET(inDialog != nil,                "DialogItem_SetTextQuietly inDialog == nil");
  634.     DUASSERT_RET(isDialogWindow(inDialog),        "DialogItem_SetTextQuietly inDialog is not a dialog"); 
  635.     DUASSERT_RET(CountDITL(inDialog) >= inItem,    "DialogItem_SetTextQuietly inItem > CountDITL(inDialog)");
  636.     DUASSERT_RET(inItem > 0,                    "DialogItem_SetTextQuietly inItem <= 0");
  637.     DUASSERT_RET(inText != nil,                    "DialogItem_SetTextQuietly inText == nil");
  638.  
  639.     Str255    oldText;
  640.     
  641.     DialogItem_GetText(inDialog, inItem, oldText);
  642.  
  643.     // if strings are identical don't set
  644.     // Boolean EqualString(str1, str2, caseSensitive, diacSensitive);
  645.     if (EqualString(inText, oldText, true, true)) { return; }
  646.     
  647.     DialogItem_SetText(inDialog, inItem, inText);
  648. }
  649.  
  650.  
  651. /*
  652.  *
  653.  * functions for working with groups of radio buttons
  654.  *
  655.  */
  656.  
  657. void DialogItem_SetRadioButtonGroup(DialogRef inDialog, DialogItemIndex inFirstItem, DialogItemIndex inLastItem, DialogItemIndex inNewItem)
  658. {
  659.     DUASSERT_RET(inDialog != nil,                        "DialogItem_SetRadioButtonGroup inDialog == nil");
  660.     DUASSERT_RET(isDialogWindow(inDialog),                "DialogItem_SetRadioButtonGroup inDialog is not a dialog"); 
  661.     DUASSERT_RET(CountDITL(inDialog) >= inFirstItem,    "DialogItem_SetRadioButtonGroup inFirstItem > CountDITL(inDialog)");
  662.     DUASSERT_RET(inFirstItem > 0,                        "DialogItem_SetRadioButtonGroup inFirstItem <= 0");
  663.     DUASSERT_RET(CountDITL(inDialog) >= inLastItem,        "DialogItem_SetRadioButtonGroup inLastItem > CountDITL(inDialog)");
  664.     DUASSERT_RET(inLastItem > 0,                        "DialogItem_SetRadioButtonGroup inLastItem <= 0");
  665.     DUASSERT_RET(inNewItem >= inFirstItem,                "DialogItem_SetRadioButtonGroup inNewItem >= inFirstItem");
  666.     DUASSERT_RET(inNewItem <= inLastItem,                "DialogItem_SetRadioButtonGroup inNewItem <= inLastItem");
  667.     
  668.     DialogItemIndex itr;
  669.     
  670.     for(itr = inFirstItem; itr <= inLastItem; itr++)
  671.     {
  672.         if (itr == inNewItem)
  673.         {
  674.             DialogItem_SetValueQuietly(inDialog, itr, 1);
  675.         }
  676.         else
  677.         {
  678.             DialogItem_SetValueQuietly(inDialog, itr, 0);
  679.         } 
  680.     }
  681. }
  682.  
  683. short DialogItem_GetRadioButtonGroup(DialogRef inDialog, DialogItemIndex inFirstItem, DialogItemIndex inLastItem)
  684. {
  685.     DUASSERT_RETVAL(inDialog != nil,                        "DialogItem_GetRadioButtonGroup inDialog == nil"                    , inFirstItem);
  686.     DUASSERT_RETVAL(isDialogWindow(inDialog),                "DialogItem_GetRadioButtonGroup inDialog is not a dialog"            , inFirstItem); 
  687.     DUASSERT_RETVAL(CountDITL(inDialog) >= inFirstItem,        "DialogItem_GetRadioButtonGroup inFirstItem > CountDITL(inDialog)"    , inFirstItem);
  688.     DUASSERT_RETVAL(inFirstItem > 0,                        "DialogItem_GetRadioButtonGroup inFirstItem <= 0"                    , inFirstItem);
  689.     DUASSERT_RETVAL(CountDITL(inDialog) >= inLastItem,        "DialogItem_GetRadioButtonGroup inLastItem > CountDITL(inDialog)"    , inFirstItem);
  690.     DUASSERT_RETVAL(inLastItem > 0,                            "DialogItem_GetRadioButtonGroup inLastItem <= 0"                    , inFirstItem);
  691.     
  692.     DialogItemIndex itr;
  693.     
  694.     for(itr = inFirstItem; itr <= inLastItem; itr++)
  695.     {
  696.         ControlValue value = DialogItem_GetValue(inDialog, itr);
  697.         
  698.         if (value) break;
  699.     }
  700.     
  701.     DUASSERT_RETVAL(itr <= inLastItem,    "DialogItem_GetRadioButtonGroup could not find a set button", inLastItem);
  702.     
  703.     return itr;
  704. }
  705.  
  706.  
  707. /*
  708.  *
  709.  * Getting/Setting dialog item min/max/value
  710.  *
  711.  */
  712.  
  713. ControlValue DialogItem_GetValue(DialogRef inDialog, DialogItemIndex inItem)
  714. {
  715.     DUASSERT_RETVAL(inDialog != nil,                "DialogItem_GetValue inDialog == nil", 0);
  716.     DUASSERT_RETVAL(isDialogWindow(inDialog),        "DialogItem_GetValue inDialog is not a dialog", 0); 
  717.     DUASSERT_RETVAL(CountDITL(inDialog) >= inItem,    "DialogItem_GetValue inItem > CountDITL(inDialog)", 0);
  718.     DUASSERT_RETVAL(inItem > 0,                        "DialogItem_GetValue inItem <= 0", 0);
  719.  
  720.     DialogItemType    type;
  721.     Handle            handle;
  722.     Rect            rect;
  723.     
  724.     GetDialogItem(inDialog, inItem, &type, &handle, &rect);
  725.     
  726.     DUASSERT_RETVAL(isControlType(type),            "DialogItem_GetValue not a control item", 0);
  727.     DUASSERT_RETVAL(handle != nil,                    "DialogItem_GetValue handle == nil", 0);
  728.     DUASSERT_RETVAL(*handle != nil,                    "DialogItem_GetValue handle was purged", 0);
  729.     
  730.     ControlValue        item_value        = 0;
  731.     ControlHandle        controlHandle    = (ControlHandle) handle;
  732.  
  733.     item_value = GetControlValue(controlHandle);
  734.     
  735.     return item_value;
  736. }
  737.  
  738. ControlValue DialogItem_GetMin(DialogRef inDialog, DialogItemIndex inItem)
  739. {
  740.     DUASSERT_RETVAL(inDialog != nil,                "DialogItem_GetMin inDialog == nil", 0);
  741.     DUASSERT_RETVAL(isDialogWindow(inDialog),        "DialogItem_GetMin inDialog is not a dialog", 0); 
  742.     DUASSERT_RETVAL(CountDITL(inDialog) >= inItem,    "DialogItem_GetMin inItem > CountDITL(inDialog)", 0);
  743.     DUASSERT_RETVAL(inItem > 0,                        "DialogItem_GetMin inItem <= 0", 0);
  744.  
  745.     DialogItemType    type;
  746.     Handle            handle;
  747.     Rect            rect;
  748.         
  749.     GetDialogItem(inDialog, inItem, &type, &handle, &rect);
  750.  
  751.     DUASSERT_RETVAL(isControlType(type),            "DialogItem_GetMin not a control item", 0);
  752.     DUASSERT_RETVAL(handle != nil,                    "DialogItem_GetMin handle == nil", 0);
  753.     DUASSERT_RETVAL(*handle != nil,                    "DialogItem_GetMin handle was purged", 0);
  754.  
  755.     short            item_min = 0;
  756.     ControlHandle    controlHandle = (ControlHandle) handle;
  757.  
  758.     item_min = GetControlMinimum(controlHandle);
  759.     
  760.     return item_min;
  761. }
  762.  
  763. ControlValue DialogItem_GetMax(DialogRef inDialog, DialogItemIndex inItem)
  764. {
  765.     DUASSERT_RETVAL(inDialog != nil,                "DialogItem_GetMax inDialog == nil", 0);
  766.     DUASSERT_RETVAL(isDialogWindow(inDialog),        "DialogItem_GetMax inDialog is not a dialog", 0); 
  767.     DUASSERT_RETVAL(CountDITL(inDialog) >= inItem,    "DialogItem_GetMax inItem > CountDITL(inDialog)", 0);
  768.     DUASSERT_RETVAL(inItem > 0,                        "DialogItem_GetMax inItem <= 0", 0);
  769.  
  770.     DialogItemType    type;
  771.     Handle            handle;
  772.     Rect            rect;
  773.     
  774.     GetDialogItem(inDialog, inItem, &type, &handle, &rect);
  775.  
  776.     DUASSERT_RETVAL(isControlType(type),            "DialogItem_GetMax not a control item", 0);
  777.     DUASSERT_RETVAL(handle != nil,                    "DialogItem_GetMax handle == nil", 0);
  778.     DUASSERT_RETVAL(*handle != nil,                    "DialogItem_GetMax handle was purged", 0);
  779.  
  780.     ControlValue    item_max         = 0;
  781.     ControlHandle    controlHandle    = (ControlHandle) handle;
  782.  
  783.     item_max = GetControlMaximum(controlHandle); 
  784.  
  785.     return item_max;
  786. }
  787.  
  788. void DialogItem_SetValue(DialogRef inDialog, DialogItemIndex inItem, ControlValue value)
  789. {
  790.     DUASSERT_RET(inDialog != nil,                    "DialogItem_SetValue inDialog == nil");
  791.     DUASSERT_RET(isDialogWindow(inDialog),            "DialogItem_SetValue inDialog is not a dialog"); 
  792.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "DialogItem_SetValue inItem > CountDITL(inDialog)");
  793.     DUASSERT_RET(inItem > 0,                        "DialogItem_SetValue inItem <= 0");
  794.  
  795.     DialogItemType        type;
  796.     Handle                handle;
  797.     Rect                rect;
  798.     
  799.     GetDialogItem(inDialog, inItem, &type, &handle, &rect);
  800.  
  801.     DUASSERT_RET(isControlType(type),                "DialogItem_SetValue not a control item");
  802.     DUASSERT_RET(handle != nil,                        "DialogItem_SetValue handle == nil");
  803.     DUASSERT_RET(*handle != nil,                    "DialogItem_SetValue handle was purged");
  804.     
  805.     ControlHandle controlHandle = (ControlHandle) handle;
  806.  
  807.     SetControlValue(controlHandle, value);
  808. }
  809.  
  810. void DialogItem_SetValueQuietly(DialogRef inDialog, DialogItemIndex inItem, ControlValue value)
  811. {
  812.     ControlValue old_value = DialogItem_GetValue(inDialog, inItem);
  813.     
  814.     if (old_value != value) { DialogItem_SetValue(inDialog, inItem, value); }
  815. }
  816.  
  817. void DialogItem_SetMin(DialogRef inDialog, DialogItemIndex inItem, ControlValue min)
  818. {
  819.     DUASSERT_RET(inDialog != nil,                "DialogItem_SetMin inDialog == nil");
  820.     DUASSERT_RET(isDialogWindow(inDialog),        "DialogItem_SetMin inDialog is not a dialog"); 
  821.     DUASSERT_RET(CountDITL(inDialog) >= inItem,    "DialogItem_SetMin inItem > CountDITL(inDialog)");
  822.     DUASSERT_RET(inItem > 0,                    "DialogItem_SetMin inItem <= 0");
  823.  
  824.     DialogItemType        type;
  825.     Handle                handle;
  826.     Rect                rect;
  827.     
  828.     GetDialogItem(inDialog, inItem, &type, &handle, &rect);
  829.     
  830.     DUASSERT_RET(isControlType(type),            "DialogItem_SetMin not a control item");
  831.     DUASSERT_RET(handle != nil,                    "DialogItem_SetMin handle == nil");
  832.     DUASSERT_RET(*handle != nil,                "DialogItem_SetMin handle was purged");
  833.     
  834.     ControlHandle controlHandle = (ControlHandle) handle;
  835.     
  836.     SetControlMinimum(controlHandle, min); 
  837. }
  838.  
  839. void DialogItem_SetMax(DialogRef inDialog, DialogItemIndex inItem, ControlValue max)
  840. {
  841.     DUASSERT_RET(inDialog != nil,                "DialogItem_SetMax inDialog == nil");
  842.     DUASSERT_RET(isDialogWindow(inDialog),        "DialogItem_SetMax inDialog is not a dialog"); 
  843.     DUASSERT_RET(CountDITL(inDialog) >= inItem,    "DialogItem_SetMax inItem > CountDITL(inDialog)");
  844.     DUASSERT_RET(inItem > 0,                    "DialogItem_SetMax inItem <= 0");
  845.  
  846.     DialogItemType        type;
  847.     Handle                handle;
  848.     Rect                rect;
  849.     
  850.     GetDialogItem(inDialog, inItem, &type, &handle, &rect);
  851.  
  852.     DUASSERT_RET(isControlType(type),            "DialogItem_SetMax not a control item");
  853.     DUASSERT_RET(handle != nil,                    "DialogItem_SetMax handle == nil");
  854.     DUASSERT_RET(*handle != nil,                "DialogItem_SetMax handle was purged");
  855.  
  856.     ControlHandle controlHandle = (ControlHandle) handle;
  857.         
  858.     SetControlMaximum(controlHandle, max);
  859. }
  860.  
  861.  
  862. /*
  863.  *
  864.  * Get/Set DialogItemIndex rect
  865.  *
  866.  */
  867.  
  868. void DialogItem_GetRect(DialogRef inDialog, DialogItemIndex inItem, Rect *outItemRect)
  869. {
  870.     DUASSERT_RET(inDialog != nil,                    "DialogItem_GetRect inDialog == nil");
  871.     DUASSERT_RET(isDialogWindow(inDialog),            "DialogItem_GetRect inDialog is not a dialog"); 
  872.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "DialogItem_GetRect inItem > CountDITL(inDialog)");
  873.     DUASSERT_RET(inItem > 0,                        "DialogItem_GetRect inItem <= 0");
  874.     DUASSERT_RET(outItemRect != nil,                "DialogItem_GetRect outItemRect == nil");
  875.  
  876.     DialogItemType        type;
  877.     Handle                handle;
  878.     Rect                rect;
  879.  
  880.     GetDialogItem(inDialog, inItem, &type, &handle, &rect);
  881.  
  882.     *outItemRect = rect;
  883. }
  884.  
  885. void DialogItem_SetRect(DialogRef inDialog, DialogItemIndex inItem, const Rect *inItemRect)
  886. {
  887.     DUASSERT_RET(inDialog != nil,                    "DialogItem_SetRect inDialog == nil");
  888.     DUASSERT_RET(isDialogWindow(inDialog),            "DialogItem_SetRect inDialog is not a dialog"); 
  889.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "DialogItem_SetRect inItem > CountDITL(inDialog)");
  890.     DUASSERT_RET(inItem > 0,                        "DialogItem_SetRect inItem <= 0");
  891.  
  892.     DialogItemType        type;
  893.     Handle                handle;
  894.     Rect                 oldRect;
  895.  
  896.     GetDialogItem(inDialog, inItem, &type, &handle, &oldRect);
  897.     SetDialogItem(inDialog, inItem, type, handle, inItemRect);
  898.  
  899.     // if this is a control offset the control rect as well    
  900.     if (isControlType(type))
  901.     {
  902.         DUASSERT_RET(handle != nil,                    "DialogItem_SetRect item was control but handle was nil");
  903.  
  904.         ControlHandle control    = (ControlHandle) handle;
  905.         Rect controlRect        = (*control)->contrlRect;
  906.         
  907.         MoveControl(control, inItemRect->left, inItemRect->top);
  908.  
  909.         SizeControl(control,    (inItemRect->right - inItemRect->left),
  910.                                 (inItemRect->bottom - inItemRect->top));
  911.     }    
  912. }
  913.  
  914. void DialogItem_OffsetRect(DialogRef inDialog, DialogItemIndex inItem, short inDeltaH, short inDeltaV)
  915. {
  916.     DUASSERT_RET(inDialog != nil,                    "OffestDialogItemRect inDialog == nil");
  917.     DUASSERT_RET(isDialogWindow(inDialog),            "OffestDialogItemRect inDialog is not a dialog"); 
  918.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "OffestDialogItemRect inItem > CountDITL(inDialog)");
  919.     DUASSERT_RET(inItem > 0,                        "OffestDialogItemRect inItem <= 0");
  920.  
  921.     DialogItem_DeltaRect(inDialog, inItem, inDeltaV, inDeltaH, inDeltaV, inDeltaH);
  922. }
  923.  
  924. void DialogItem_DeltaRect(DialogRef inDialog, DialogItemIndex inItem, short inTop, short inLeft, short inBottom, short inRight)
  925. {    
  926.     DUASSERT_RET(inDialog != nil,                    "DialogItem_DeltaRect inDialog == nil");
  927.     DUASSERT_RET(isDialogWindow(inDialog),            "DialogItem_DeltaRect inDialog is not a dialog"); 
  928.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "DialogItem_DeltaRect inItem > CountDITL(inDialog)");
  929.     DUASSERT_RET(inItem > 0,                        "DialogItem_DeltaRect inItem <= 0");
  930.  
  931.     Rect        rect;
  932.     
  933.     DialogItem_GetRect(inDialog, inItem, &rect);
  934.  
  935.     rect.top    += inTop;
  936.     rect.left    += inLeft;
  937.     rect.bottom    += inBottom;
  938.     rect.right    += inRight;
  939.  
  940.     DialogItem_SetRect(inDialog, inItem, &rect);
  941.  
  942. short DialogItem_GetWidth(DialogRef inDialog, DialogItemIndex inItem)
  943. {
  944.     DUASSERT_RETVAL(inDialog != nil,                "DialogItem_GetWidth inDialog == nil", 0);
  945.     DUASSERT_RETVAL(isDialogWindow(inDialog),        "DialogItem_GetWidth inDialog is not a dialog",0); 
  946.     DUASSERT_RETVAL(CountDITL(inDialog) >= inItem,    "DialogItem_GetWidth inItem > CountDITL(inDialog)", 0);
  947.     DUASSERT_RETVAL(inItem > 0,                        "DialogItem_GetWidth inItem <= 0", 0);
  948.  
  949.     Rect        rect;
  950.     short        width;
  951.     
  952.     DialogItem_GetRect(inDialog, inItem, &rect);
  953.     
  954.     width = rect.right - rect.left;
  955.     
  956.     return width;    
  957. }
  958.  
  959. /*
  960.  *
  961.  * validate/invalidate
  962.  *
  963.  *
  964.  */
  965.  
  966. void DialogItem_Invalidate(DialogRef inDialog, DialogItemIndex inItem)
  967. {
  968.     DUASSERT_RET(inDialog != nil,                    "DialogItem_Invalidate inDialog == nil");
  969.     DUASSERT_RET(isDialogWindow(inDialog),            "DialogItem_Invalidate inDialog is not a dialog"); 
  970.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "DialogItem_Invalidate inItem > CountDITL(inDialog)");
  971.     DUASSERT_RET(inItem > 0,                        "DialogItem_Invalidate inItem <= 0");
  972.  
  973.     Rect rect;
  974.     GWorldState    saved_gworld(inDialog);    // stack based class
  975.  
  976.     DialogItem_GetRect(inDialog, inItem, &rect);
  977.     InvalRect(&rect);
  978. }
  979.  
  980. void DialogItem_Valididate(DialogRef inDialog, DialogItemIndex inItem)
  981. {
  982.     DUASSERT_RET(inDialog != nil,                    "DialogItem_Valididate inDialog == nil");
  983.     DUASSERT_RET(isDialogWindow(inDialog),            "DialogItem_Valididate inDialog is not a dialog"); 
  984.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "DialogItem_Valididate inItem > CountDITL(inDialog)");
  985.     DUASSERT_RET(inItem > 0,                        "DialogItem_Valididate inItem <= 0");
  986.  
  987.     Rect rect;
  988.     GWorldState    saved_gworld(inDialog);    // stack based class
  989.  
  990.     DialogItem_GetRect(inDialog, inItem, &rect);
  991.     ValidRect(&rect);
  992. }
  993.  
  994. void DialogItem_Show(DialogRef inDialog, DialogItemIndex inItem)
  995. {
  996.     DUASSERT_RET(inDialog != nil,                    "DialogItem_Show inDialog == nil");
  997.     DUASSERT_RET(isDialogWindow(inDialog),            "DialogItem_Show inDialog is not a dialog"); 
  998.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "DialogItem_Show inItem > CountDITL(inDialog)");
  999.     DUASSERT_RET(inItem > 0,                        "DialogItem_Show inItem <= 0");
  1000.  
  1001.     ShowDialogItem(inDialog, inItem);
  1002. }
  1003.  
  1004. void DialogItem_Hide(DialogRef inDialog, DialogItemIndex inItem)
  1005. {
  1006.     DUASSERT_RET(inDialog != nil,                    "DialogItem_Hide inDialog == nil");
  1007.     DUASSERT_RET(isDialogWindow(inDialog),            "DialogItem_Hide inDialog is not a dialog"); 
  1008.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "DialogItem_Hide inItem > CountDITL(inDialog)");
  1009.     DUASSERT_RET(inItem > 0,                        "DialogItem_Hide inItem <= 0");
  1010.  
  1011.     HideDialogItem(inDialog, inItem);
  1012. }
  1013.  
  1014. DialogItemType DialogItem_GetType(DialogRef inDialog, DialogItemIndex inItem)
  1015. {
  1016.     DUASSERT_RETVAL(inDialog != nil,                "DialogItem_SetType inDialog == nil",nil);
  1017.     DUASSERT_RETVAL(isDialogWindow(inDialog),        "DialogItem_SetType inDialog is not a dialog",nil); 
  1018.     DUASSERT_RETVAL(CountDITL(inDialog) >= inItem,    "DialogItem_SetType inItem > CountDITL(inDialog)",nil);
  1019.     DUASSERT_RETVAL(inItem > 0,                        "DialogItem_SetType inItem <= 0",nil);
  1020.     
  1021.     DialogItemType        type;
  1022.     Handle                handle;
  1023.     Rect                rect;
  1024.     
  1025.     GetDialogItem(inDialog, inItem, &type, &handle, &rect);
  1026.     
  1027.     return type;
  1028. }
  1029.  
  1030. void DialogItem_SetType(DialogRef inDialog, DialogItemIndex inItem, DialogItemType inType)
  1031. {
  1032.     DUASSERT_RET(inDialog != nil,                    "DialogItem_SetType inDialog == nil");
  1033.     DUASSERT_RET(isDialogWindow(inDialog),            "DialogItem_SetType inDialog is not a dialog"); 
  1034.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "DialogItem_SetType inItem > CountDITL(inDialog)");
  1035.     DUASSERT_RET(inItem > 0,                        "DialogItem_SetType inItem <= 0");
  1036.     
  1037.     DialogItemType        oldType;
  1038.     Handle                handle;
  1039.     Rect                rect;
  1040.     
  1041.     GetDialogItem(inDialog, inItem, &oldType, &handle, &rect);
  1042.     SetDialogItem(inDialog, inItem, inType, handle, &rect);
  1043. }
  1044.  
  1045. // getting and setting the default item
  1046. DialogItemIndex        Dialog_GetDefaultItem(DialogRef inDialog)
  1047. {
  1048.     DUASSERT_RETVAL(inDialog != nil,                "Dialog_SetDefaultItem inDialog == nil", 0);
  1049.     DUASSERT_RETVAL(isDialogWindow(inDialog),        "Dialog_GetDefaultItem inDialog is not a dialog", 0); 
  1050.  
  1051.     DialogItemIndex defaultItem;
  1052.  
  1053.     defaultItem = GetDialogDefaultItem(inDialog);
  1054.     
  1055.     return defaultItem;
  1056. }
  1057.  
  1058. DialogItemIndex        Dialog_GetCancelItem(DialogRef inDialog)
  1059. {
  1060.     DUASSERT_RETVAL(inDialog != nil,                "Dialog_GetCancelItem inDialog == nil", 0);
  1061.     DUASSERT_RETVAL(isDialogWindow(inDialog),        "Dialog_GetCancelItem inDialog is not a dialog", 0); 
  1062.  
  1063.     DialogItemIndex cancelItem;
  1064.     
  1065.     cancelItem = GetDialogCancelItem(inDialog);
  1066.     
  1067.     return cancelItem;
  1068. }
  1069.  
  1070. void Dialog_SetDefaultItem(DialogRef inDialog, DialogItemIndex inItem)
  1071. {
  1072.     DUASSERT_RET(inDialog != nil,                    "Dialog_SetDefaultItem inDialog == nil");
  1073.     DUASSERT_RET(isDialogWindow(inDialog),            "Dialog_SetDefaultItem inDialog is not a dialog"); 
  1074.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "Dialog_SetDefaultItem inItem > CountDITL(inDialog)");
  1075.     DUASSERT_RET(inItem >= 0,                        "Dialog_SetDefaultItem inItem < 0");
  1076.  
  1077.     SetDialogDefaultItem(inDialog, inItem);
  1078. }
  1079.  
  1080. void Dialog_SetCancelItem(DialogRef inDialog, DialogItemIndex inItem)
  1081. {
  1082.     DUASSERT_RET(inDialog != nil,                    "Dialog_SetCancelItem inDialog == nil");
  1083.     DUASSERT_RET(isDialogWindow(inDialog),            "Dialog_SetCancelItem inDialog is not a dialog"); 
  1084.     DUASSERT_RET(CountDITL(inDialog) >= inItem,        "Dialog_SetCancelItem inItem > CountDITL(inDialog)");
  1085.     DUASSERT_RET(inItem >= 0,                        "Dialog_SetCancelItem inItem < 0");
  1086.  
  1087.     SetDialogCancelItem(inDialog, inItem);
  1088. }
  1089.  
  1090. void Dialog_SetTracksCursor(DialogRef inDialog, Boolean tracks)
  1091. {
  1092.     DUASSERT_RET(inDialog != nil,                    "Dialog_SetTrackCursor inDialog == nil");
  1093.     DUASSERT_RET(isDialogWindow(inDialog),            "Dialog_SetTrackCursor inDialog is not a dialog"); 
  1094.  
  1095.     SetDialogTracksCursor(inDialog, tracks);
  1096. }
  1097.  
  1098. void Window_Validate(WindowRef inWindow)
  1099. {
  1100.     DUASSERT_RET(inWindow != nil,                    "Window_Validate inWindow == nil");
  1101.  
  1102.     GWorldState    savedGWorld(inWindow);                    // stack based class
  1103.     CGrafPtr    windowPort    = GetWindowPort(inWindow);
  1104.     Rect        bounds        = windowPort->portRect;
  1105.  
  1106.     ValidRect(&bounds);
  1107. }
  1108.  
  1109. void Window_Invalidate(WindowRef inWindow)
  1110. {
  1111.     DUASSERT_RET(inWindow != nil,                    "Window_Validate inWindow == nil");
  1112.  
  1113.     GWorldState    savedGWorld(inWindow);                    // stack based class
  1114.     CGrafPtr    windowPort    = GetWindowPort(inWindow);
  1115.     Rect        bounds        = windowPort->portRect;
  1116.  
  1117.     InvalRect(&bounds);
  1118. }
  1119.  
  1120. void GScForeColor_Set(GScGrayRamp color)
  1121. {
  1122.     DUASSERT_RET(color >= GScRampWhite,    "GScForeColor_Set color to small");
  1123.     DUASSERT_RET(color <= GScRampBlack,    "GScForeColor_Set color to large");
  1124.  
  1125.     UInt16 theGrayColor        = (0x1111) * (0xf - color);
  1126.     RGBColor newForeColor    = {theGrayColor, theGrayColor, theGrayColor};
  1127.     
  1128.     RGBForeColor(&newForeColor);
  1129. }
  1130.  
  1131. void GScBackColor_Set(GScGrayRamp color)
  1132. {
  1133.     DUASSERT_RET(color >= GScRampWhite,    "GScBackColor_Set color to small");
  1134.     DUASSERT_RET(color <= GScRampBlack,    "GScBackColor_Set color to large");
  1135.  
  1136.     UInt16 theGrayColor     = (0x1111) * (0xf - color);
  1137.     RGBColor newForeColor    = {theGrayColor, theGrayColor, theGrayColor};
  1138.     
  1139.     RGBBackColor(&newForeColor);
  1140. }
  1141.  
  1142. void    GScTopLeft_Draw(const Rect *r, GScGrayRamp inColor)
  1143. {
  1144.     QDColorState    stackColorSaver;    // saves and restore color w/ stack based object
  1145.     QDPenState        stackPenSaver;        // saves and restore pen w/ stack based object
  1146.     QDPenState::Clear();                // clear the pen state
  1147.  
  1148.     GScForeColor_Set(inColor);
  1149.  
  1150.     MoveTo(r->left, r->top);
  1151.     LineTo(r->right - 2, r->top);
  1152.  
  1153.     MoveTo(r->left, r->top);
  1154.     LineTo(r->left, r->bottom -2);
  1155. }
  1156.  
  1157. void    GScBotRight_Draw(const Rect *r, GScGrayRamp inColor)
  1158. {
  1159.     QDColorState    stackColorSaver;    // saves and restore color w/ stack based object
  1160.     QDPenState        stackPenSaver;        // saves and restore pen w/ stack based object
  1161.     QDPenState::Clear();                // clear the pen state
  1162.  
  1163.     GScForeColor_Set(inColor);
  1164.  
  1165.     MoveTo(r->right - 1, r->bottom - 1);
  1166.     LineTo(r->right - 1, r->top + 1);
  1167.         
  1168.     MoveTo(r->right - 1, r->bottom - 1);
  1169.     LineTo(r->left + 1, r->bottom - 1);
  1170. }
  1171.  
  1172. void GScGroupBox_PrimarySimple_Draw(const Rect *r, GScActiveType active)
  1173. {
  1174.     QDColorState    stackColorSaver;    // saves and restore color w/ stack based object
  1175.     QDPenState        stackPenSaver;        // saves and restore pen w/ stack based object
  1176.     QDPenState::Clear();                // clear the pen state
  1177.     
  1178.     if (active) { GScForeColor_Set(GScRamp7); }
  1179.     else        { GScForeColor_Set(GScRamp4); }
  1180.  
  1181.     MoveTo(r->left, r->top);
  1182.     LineTo(r->right - 2, r->top);
  1183.     LineTo(r->right - 2, r->bottom - 2);
  1184.     LineTo(r->left, r->bottom - 2);
  1185.     LineTo(r->left, r->top);
  1186.         
  1187.     if (active) { GScForeColor_Set(GScRampWhite);    }
  1188.     else        { GScForeColor_Set(GScRampBG);         }    // background color
  1189.  
  1190.     MoveTo(r->left + 1, r->top + 1);
  1191.     LineTo(r->right - 3, r->top + 1);
  1192.  
  1193.     MoveTo(r->left + 1, r->top + 1);
  1194.     LineTo(r->left + 1, r->bottom - 3);
  1195.         
  1196.     MoveTo(r->right - 1, r->bottom - 1);
  1197.     LineTo(r->right - 1, r->top + 1);
  1198.         
  1199.     MoveTo(r->right - 1, r->bottom - 1);
  1200.     LineTo(r->left + 1, r->bottom - 1);
  1201. }
  1202.  
  1203. void GScGroupBox_PrimaryNamed_Draw(const Rect *r, const Str255 string, GScActiveType active)
  1204. {
  1205.     QDColorState    stackColorSaver;    // saves and restore color w/ stack based object
  1206.     QDPenState        stackPenSaver;        // saves and restore pen w/ stack based object
  1207.     QDPenState::Clear();                // clear the pen state
  1208.     
  1209.     if (active)    { GScForeColor_Set(GScRamp7); }
  1210.     else        { GScForeColor_Set(GScRamp4); }
  1211.     
  1212.     MoveTo(r->left, r->top);
  1213.     LineTo(r->left + 8, r->top);
  1214.  
  1215.     // leave a small border around string (and offset baseline down one pixel)
  1216.     if (active)    { GScForeColor_Set(GScRampBlack);    }
  1217.     else        { GScForeColor_Set(GScRamp7);        }
  1218.     
  1219.     Move(2, 1);
  1220.     DrawString(string);
  1221.     Move(1, -1);
  1222.     
  1223.     Point rightEdgeText;
  1224.     GetPen (&rightEdgeText);
  1225.     
  1226.     if (active)    { GScForeColor_Set(GScRamp7); }
  1227.     else        { GScForeColor_Set(GScRamp4); }
  1228.  
  1229.     // draw first rectangle
  1230.     LineTo(r->right - 2, r->top);
  1231.     LineTo(r->right - 2, r->bottom - 2);
  1232.     LineTo(r->left, r->bottom - 2);
  1233.     LineTo(r->left, r->top);
  1234.     
  1235.     if (active)    { GScForeColor_Set(GScRampWhite);    }
  1236.     else        { GScForeColor_Set(GScRampBG);        }
  1237.  
  1238.     MoveTo(r->left + 1, r->top + 1);
  1239.     LineTo(r->left + 8, r->top + 1);
  1240.     MoveTo(rightEdgeText.h, r->top + 1);
  1241.     LineTo(r->right - 3, r->top + 1);
  1242.  
  1243.     MoveTo(r->left + 1, r->top + 1);
  1244.     LineTo(r->left + 1, r->bottom - 3);
  1245.     
  1246.     MoveTo(r->right - 1, r->bottom - 1);
  1247.     LineTo(r->right - 1, r->top + 1);
  1248.     
  1249.     MoveTo(r->right - 1, r->bottom - 1);
  1250.     LineTo(r->left + 1, r->bottom - 1);
  1251. }
  1252.  
  1253. void GScGroupBox_SecondarySimple_Draw(const Rect *r, GScActiveType active)
  1254. {
  1255.     GScGrayRamp        topLeftColor;
  1256.     GScGrayRamp        botRightColor;    
  1257.     
  1258.     // top & left
  1259.     if (active)        { topLeftColor = GScRamp7; }
  1260.     else            { topLeftColor = GScRamp4; }
  1261.  
  1262.     GScTopLeft_Draw(r, topLeftColor);
  1263.  
  1264.     // bottom and right
  1265.     if (active)        { botRightColor = GScRampWhite;    }
  1266.     else            { botRightColor = GScRamp4;        }
  1267.     
  1268.     GScBotRight_Draw(r, botRightColor);
  1269. }
  1270.  
  1271. void GScGroupBox_SecondaryNamed_Draw(const Rect *r, const Str255 string, GScActiveType active)
  1272. {
  1273.     QDColorState    stackColorSaver;    // saves and restore color w/ stack based object
  1274.     QDPenState        stackPenSaver;        // saves and restore pen w/ stack based object
  1275.     QDPenState::Clear();                // clear the pen state
  1276.  
  1277.     if (active) { GScForeColor_Set(GScRamp7); }
  1278.     else        { GScForeColor_Set(GScRamp4); }
  1279.     
  1280.     MoveTo(r->left, r->top);
  1281.     LineTo(r->left + 8, r->top);
  1282.  
  1283.     // leave a small border around string (and offset baseline down one pixel)
  1284.     if (active)    { GScForeColor_Set(GScRampBlack);    }
  1285.     else        { GScForeColor_Set(GScRamp7);        }
  1286.  
  1287.     Move(2, 1);
  1288.     DrawString(string);
  1289.     Move(1, -1);
  1290.  
  1291.     if (active)    { GScForeColor_Set(GScRamp7); }
  1292.     else        { GScForeColor_Set(GScRamp4); }
  1293.     
  1294.     LineTo(r->right - 2, r->top);
  1295.  
  1296.     MoveTo(r->left, r->top);
  1297.     LineTo(r->left, r->bottom -2);
  1298.     
  1299.     if (active) { GScForeColor_Set(GScRampWhite);    }
  1300.     else        { GScForeColor_Set(GScRamp4);        }
  1301.     
  1302.     // bottom & right side
  1303.     MoveTo(r->right - 1, r->bottom - 1);
  1304.     LineTo(r->right - 1, r->top + 1);
  1305.     
  1306.     MoveTo(r->right - 1, r->bottom - 1);
  1307.     LineTo(r->left + 1, r->bottom - 1);
  1308. }
  1309.  
  1310. void    GScTextEntryFrame_Draw(const Rect *r, GScActiveType active)
  1311. {
  1312.     QDColorState    stackColorSaver;    // saves and restore color w/ stack based object
  1313.     QDPenState        stackPenSaver;        // saves and restore pen w/ stack based object
  1314.     QDPenState::Clear();                // clear the pen state
  1315.  
  1316.     Rect insetRect = *r;
  1317.     InsetRect(&insetRect, 1, 1);
  1318.     
  1319.     if (active)
  1320.     {
  1321.         GScTopLeft_Draw(r, GScRamp5);
  1322.         GScBotRight_Draw(r, GScRampWhite);
  1323.         
  1324.         GScForeColor_Set(GScRampBlack);
  1325.         FrameRect(&insetRect);
  1326.     }
  1327.     else
  1328.     {
  1329.         GScForeColor_Set(GScRampBG);
  1330.         FrameRect(r);
  1331.     
  1332.         GScForeColor_Set(GScRamp10);
  1333.         FrameRect(&insetRect);
  1334.     }
  1335. }
  1336.  
  1337.  
  1338.  
  1339.  
  1340. /****************************************** EASY COPY BITS FUNCTIONS ******************************************/
  1341.  
  1342. /*
  1343.  *
  1344.  * CopyBitsLite
  1345.  *
  1346.  * Copy bits from source to dest, does not colorize and sets port to the dst before
  1347.  * it does the copy.
  1348.  *
  1349.  */
  1350.  
  1351. void CopyBitsLite(CGrafPtr src, CGrafPtr dst, const Rect *srcRect, const Rect *dstRect)
  1352. {
  1353.     DUASSERT_RET(src != nil,        "CopyBitsLite src was nil");
  1354.     DUASSERT_RET(dst != nil,        "CopyBitsLite dst was nil");
  1355.  
  1356.     GrafPtr srcGrafPort = (GrafPtr) src;            // casting of our CGrafPtrs to GrafPtr
  1357.     GrafPtr dstGrafPort = (GrafPtr) dst;
  1358.  
  1359.     GWorldState stack_port_saver(dstGrafPort);        // set the port to the dest and save old port
  1360.  
  1361.     {
  1362.         QDColorState stack_color_saver;                // save old colors
  1363.         QDColorState::Clear();                        // set fore/back color to black/white
  1364.  
  1365.         CopyBits(&srcGrafPort->portBits, &dstGrafPort->portBits, srcRect, dstRect, srcCopy, nil);
  1366.         DUASSERT(QDErr() == noErr, "CopyBits gave an error inside CopyBitsLite");
  1367.     }
  1368. }
  1369.  
  1370. void CopyBitsLiteWithColor(CGrafPtr src, CGrafPtr dst, const Rect *srcRect, const Rect *dstRect, const RGBColor *inColor)
  1371. {
  1372.     DUASSERT_RET(src != nil,        "CopyBitsLiteWithColor src was nil");
  1373.     DUASSERT_RET(dst != nil,        "CopyBitsLiteWithColor dst was nil");
  1374.  
  1375.     GrafPtr srcGrafPort = (GrafPtr) src;            // casting of our CGrafPtrs to GrafPtr
  1376.     GrafPtr dstGrafPort = (GrafPtr) dst;
  1377.  
  1378.     GWorldState stack_port_saver(dstGrafPort);        // set the port to the dest and save old port
  1379.  
  1380.     {
  1381.         QDColorState stack_color_saver;                // save old colors
  1382.  
  1383.         RGBForeColor(inColor);                        // set fore/back color to in color/white
  1384.         BackColor(whiteColor);                                
  1385.  
  1386.         CopyBits(&srcGrafPort->portBits, &dstGrafPort->portBits, srcRect, dstRect, srcCopy, nil);
  1387.         DUASSERT(QDErr() == noErr, "CopyBits gave an error inside CopyBitsLiteWithColor");
  1388.     }
  1389. }
  1390.  
  1391. QDColorState::QDColorState()
  1392. {
  1393.     // color
  1394.     ::SaveFore(&mForegroundColor);
  1395.     ::SaveBack(&mBackgroundColor);
  1396. }
  1397.  
  1398.  
  1399. QDColorState::~QDColorState()
  1400. {
  1401.     // color
  1402.     ::RestoreFore(&mForegroundColor);
  1403.     ::RestoreBack(&mBackgroundColor);
  1404. }
  1405.  
  1406. void
  1407. QDColorState::Clear()
  1408. {
  1409.     ::ForeColor(blackColor);
  1410.     ::BackColor(whiteColor);
  1411. }
  1412.  
  1413. QDTextState::QDTextState()
  1414. {
  1415.     GrafPtr        port;
  1416.     GetPort(&port);
  1417.  
  1418.     mFontID        = port->txFont;
  1419.     mFace        = port->txFace;
  1420.     mMode        = port->txMode;
  1421.     mSize        = port->txSize;
  1422. }
  1423.  
  1424.  
  1425. QDTextState::~QDTextState()
  1426. {
  1427.     ::TextFont(mFontID);
  1428.     ::TextFace(mFace);
  1429.     ::TextMode(mMode);
  1430.     ::TextSize(mSize);
  1431. }
  1432.  
  1433. void QDTextState::Clear()
  1434. {
  1435.     ::TextFont(systemFont);
  1436.     ::TextFace(0);
  1437.     ::TextMode(srcOr);
  1438.     ::TextSize(0);
  1439. }
  1440.  
  1441. QDPenState::QDPenState(void)
  1442. {
  1443.     ::GetPenState(&mPenState);
  1444. }
  1445.  
  1446. QDPenState::~QDPenState(void)
  1447. {
  1448.     ::SetPenState(&mPenState);
  1449. }
  1450.  
  1451. void QDPenState::Clear(void)
  1452. {
  1453.     ::MoveTo(0,0);
  1454.     ::PenNormal();
  1455. }
  1456.  
  1457. GWorldState::GWorldState(void)
  1458. {
  1459.     GetGWorld(&mPort, &mGDH);
  1460. }
  1461.  
  1462. GWorldState::GWorldState(GrafPtr inNewPort)
  1463. {
  1464.     GetGWorld(&mPort, &mGDH);
  1465.  
  1466.     if (isColorPort(inNewPort))
  1467.     {
  1468.         SetGWorld((CGrafPtr) inNewPort, nil);
  1469.     }
  1470.     else
  1471.     {
  1472.         SetPort (inNewPort);
  1473.     }
  1474. }
  1475.  
  1476. GWorldState::~GWorldState()
  1477. {
  1478.     SetGWorld(mPort, mGDH);
  1479. }
  1480.  
  1481. #if __MWERKS__
  1482. #pragma optimize_for_size reset
  1483. #endif
  1484.